package com.xxx.video.dynamic.presenters;

import android.content.Context;

import androidx.annotation.NonNull;

import com.xxx.video.commen.beans.BaseBean;
import com.xxx.video.commen.presenters.BasePresenter;
import com.xxx.video.commen.utils.ResponseUtils;
import com.xxx.video.commen.views.AddFriendExtraMessageDialog;
import com.xxx.video.dynamic.beans.FriendListBean;
import com.xxx.video.network.listeners.CommonResponseListener;
import com.xxx.video.network.utils.NetWorkUtils;

public class MyFriendPresenter extends BasePresenter<IMyFriendView> {

    public MyFriendPresenter(@NonNull Context context, IMyFriendView baseView) {
        super(context, baseView);
    }

    /**
     * get friend list
     *
     * @param page page
     */
    public void getFriendsList(int page) {
        NetWorkUtils.getInstance().getFriendsList(String.valueOf(page), new CommonResponseListener<FriendListBean>() {
            @Override
            public void onSuccess(FriendListBean successOb, String result) {
                if (ResponseUtils.getInstance().isNoError(successOb)) {
                    if (getBaseView() != null) {
                        getBaseView().initData2View(successOb.page);
                    }
                }
            }

            @Override
            public void onFailure(Object failureObj) {
            }
        });
    }

    /**
     * get recommend  friend list
     */
    public void recommendFriends() {
        NetWorkUtils.getInstance().recommendFriends(String.valueOf(1), new CommonResponseListener<FriendListBean>() {
            @Override
            public void onSuccess(FriendListBean successOb, String result) {
                if (ResponseUtils.getInstance().isNoError(successOb)) {
                    if (getBaseView() != null) {
                        getBaseView().initRecommendFriendList(successOb.page);
                    }
                }
            }

            @Override
            public void onFailure(Object failureObj) {
            }
        });
    }

    /**
     * get near by user
     *
     * @param page page
     * @param lon  lon
     * @param lan  lan
     */
    public void nearbyUser(String page, String lon, String lan) {
        NetWorkUtils.getInstance().nearbyUser(page, lon, lan, new CommonResponseListener<FriendListBean>() {
            @Override
            public void onSuccess(FriendListBean successOb, String result) {
                if (ResponseUtils.getInstance().isNoError(successOb)) {
                    if (getBaseView() != null) {
                        getBaseView().initPeopleNearbyList(successOb.page);
                    }
                }
            }

            @Override
            public void onFailure(Object failureObj) {
            }
        });
    }

    public void addFriends(FriendListBean.PageBean.ListBean listBean, int position, int type) {
        AddFriendExtraMessageDialog addFriendExtraMessageDialog = new AddFriendExtraMessageDialog(context);
        addFriendExtraMessageDialog.show();
        addFriendExtraMessageDialog.setOnButtonClickListener(message -> NetWorkUtils.getInstance().addFriends(listBean.userId, listBean.username, listBean.nickName, listBean.picUrl, message, new CommonResponseListener<BaseBean>() {

            @Override
            public void onSuccess(BaseBean successOb, String result) {
                if (ResponseUtils.getInstance().isNoError(successOb)) {
                    if (getBaseView() != null) {
                        getBaseView().addFriendSuccess(position,type);
                    }
                }
            }

            @Override
            public void onFailure(Object failureObj) {

            }
        }));
    }
}
